$(function() {
searchAllApp();

initTable();
});

/**
* 初始化表格
*/
function initTable() {
$('#hot_keyTable').DataTable({
language: Language,
columns: [
        {
        "data": "appName",
        "title": "app名称"
        },
        {
        "data": "key",
        "title": "key"
        },
        {
        "data": "enable",
        "title": "状态",
        "render": function (data, type, row, meta) {
                if (data) {
                        return "已启用"
                } else {
                        return "已禁用"
                }
        }
        },
        {
        "data": "duration",
        "title": "缓存时间（秒）"
        },
        {
        "data": "desc",
        "title": "描述"
        },
        {
        "data": "createTime",
        "title": "创建时间"
        },
        {
        "data": "updateTime",
        "title": "修改时间"
        },
{
"data": "null",
"title": "操作",
"render": function (data, type, row, meta) {
return `<button class="btn btn-danger" style="margin-right: 5px" onClick="remove('${row.id}')">删除</button>` +
`<button class="btn btn-primary" data-toggle="modal" data-target="#updateModal" onClick="modifyShow(this)">修改</button>`
}
}
],
dom: 'rt<"bottom"ilp><"clear">',
destroy : true,
searching: false,
processing : true,
serverSide: true,
bSort: false,
lengthMenu: [10],
autoWidth: false,


ajax: {
type: "post",
contentType: "application/json",
headers: getHeaders(),
url: searchUrl,
dataFilter: dataFilterFunc,
data: function(param) {
let json = $("#hot_keyForm").serializeObject()
json.type = 0;
json.pageNum = param.start / 10 + 1;
json.pageSize = param.length;
json.orderByKey = "id"
return JSON.stringify(json)
},
error: errorFunc
}
});
}

/**
* 查询
*/
function search() {
reloadTable('hot_keyTable');
}

/**
* 重置
*/
function reset() {
clearForm();

search();
}

/**
* 清空表单
*/
function clearForm() {
resetForm("hot_keyForm")
}

function modifyShow(_this) {
let tr = $(_this).parent().parent();
let row = getRowDataTable('hot_keyTable', tr);
loadForm("updateForm", row)
}


